{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append('..')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "from configure.settings import DBSelector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [],
   "source": [
    "db = DBSelector()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [],
   "source": [
    "conn = db.get_engine(db='db_stock')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_sql('tb_cb_index_test',con=conn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "           日期       指数  成交额(亿元)      涨跌    涨跌额  转债数目     剩余规模\n",
       "0  2017-12-29  1000.00   10.581   0.000  0.000  36.0  853.790\n",
       "1  2018-01-02  1008.83   13.936   8.831  0.883  36.0  690.602\n",
       "2  2018-01-03  1018.81   15.964   9.977  0.989  37.0  691.246\n",
       "3  2018-01-04  1024.34   15.495   5.536  0.543  38.0  700.443\n",
       "4  2018-01-05  1034.66   19.973  10.311  1.007  38.0  700.443\n",
       "5  2018-01-08  1035.65   20.513   0.990  0.096  37.0  698.595\n",
       "6  2018-01-09  1029.98   12.011  -5.668 -0.547  37.0  698.595\n",
       "7  2018-01-10  1025.42   17.635  -4.556 -0.442  38.0  717.324\n",
       "8  2018-01-11  1026.64   14.397   1.220  0.119  38.0  717.324\n",
       "9  2018-01-12  1025.85   12.904  -0.789 -0.077  38.0  717.324\n",
       "10 2018-01-15  1013.79   22.619 -12.063 -1.176  39.0  717.432\n",
       "11 2018-01-16  1015.89   15.827   2.099  0.207  41.0  756.974\n",
       "12 2018-01-17  1015.57   24.303  -0.317 -0.031  42.0  768.954\n",
       "13 2018-01-18  1022.12   22.432   6.547  0.645  43.0  806.120\n",
       "14 2018-01-19  1027.75   28.810   5.634  0.551  43.0  806.120\n",
       "15 2018-01-22  1039.47   32.225  11.716  1.140  44.0  815.398\n",
       "16 2018-01-23  1045.08   46.129   5.615  0.540  45.0  815.834\n",
       "17 2018-01-24  1055.25   43.476  10.167  0.973  45.0  815.834\n",
       "18 2018-01-25  1062.06   38.987   6.812  0.646  45.0  815.834\n",
       "19 2018-01-26  1060.13   31.229  -1.932 -0.182  46.0  825.832"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>指数</th>\n      <th>成交额(亿元)</th>\n      <th>涨跌</th>\n      <th>涨跌额</th>\n      <th>转债数目</th>\n      <th>剩余规模</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2017-12-29</td>\n      <td>1000.00</td>\n      <td>10.581</td>\n      <td>0.000</td>\n      <td>0.000</td>\n      <td>36.0</td>\n      <td>853.790</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2018-01-02</td>\n      <td>1008.83</td>\n      <td>13.936</td>\n      <td>8.831</td>\n      <td>0.883</td>\n      <td>36.0</td>\n      <td>690.602</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2018-01-03</td>\n      <td>1018.81</td>\n      <td>15.964</td>\n      <td>9.977</td>\n      <td>0.989</td>\n      <td>37.0</td>\n      <td>691.246</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2018-01-04</td>\n      <td>1024.34</td>\n      <td>15.495</td>\n      <td>5.536</td>\n      <td>0.543</td>\n      <td>38.0</td>\n      <td>700.443</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2018-01-05</td>\n      <td>1034.66</td>\n      <td>19.973</td>\n      <td>10.311</td>\n      <td>1.007</td>\n      <td>38.0</td>\n      <td>700.443</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>2018-01-08</td>\n      <td>1035.65</td>\n      <td>20.513</td>\n      <td>0.990</td>\n      <td>0.096</td>\n      <td>37.0</td>\n      <td>698.595</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>2018-01-09</td>\n      <td>1029.98</td>\n      <td>12.011</td>\n      <td>-5.668</td>\n      <td>-0.547</td>\n      <td>37.0</td>\n      <td>698.595</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>2018-01-10</td>\n      <td>1025.42</td>\n      <td>17.635</td>\n      <td>-4.556</td>\n      <td>-0.442</td>\n      <td>38.0</td>\n      <td>717.324</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>2018-01-11</td>\n      <td>1026.64</td>\n      <td>14.397</td>\n      <td>1.220</td>\n      <td>0.119</td>\n      <td>38.0</td>\n      <td>717.324</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>2018-01-12</td>\n      <td>1025.85</td>\n      <td>12.904</td>\n      <td>-0.789</td>\n      <td>-0.077</td>\n      <td>38.0</td>\n      <td>717.324</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>2018-01-15</td>\n      <td>1013.79</td>\n      <td>22.619</td>\n      <td>-12.063</td>\n      <td>-1.176</td>\n      <td>39.0</td>\n      <td>717.432</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>2018-01-16</td>\n      <td>1015.89</td>\n      <td>15.827</td>\n      <td>2.099</td>\n      <td>0.207</td>\n      <td>41.0</td>\n      <td>756.974</td>\n    </tr>\n    <tr>\n      <th>12</th>\n      <td>2018-01-17</td>\n      <td>1015.57</td>\n      <td>24.303</td>\n      <td>-0.317</td>\n      <td>-0.031</td>\n      <td>42.0</td>\n      <td>768.954</td>\n    </tr>\n    <tr>\n      <th>13</th>\n      <td>2018-01-18</td>\n      <td>1022.12</td>\n      <td>22.432</td>\n      <td>6.547</td>\n      <td>0.645</td>\n      <td>43.0</td>\n      <td>806.120</td>\n    </tr>\n    <tr>\n      <th>14</th>\n      <td>2018-01-19</td>\n      <td>1027.75</td>\n      <td>28.810</td>\n      <td>5.634</td>\n      <td>0.551</td>\n      <td>43.0</td>\n      <td>806.120</td>\n    </tr>\n    <tr>\n      <th>15</th>\n      <td>2018-01-22</td>\n      <td>1039.47</td>\n      <td>32.225</td>\n      <td>11.716</td>\n      <td>1.140</td>\n      <td>44.0</td>\n      <td>815.398</td>\n    </tr>\n    <tr>\n      <th>16</th>\n      <td>2018-01-23</td>\n      <td>1045.08</td>\n      <td>46.129</td>\n      <td>5.615</td>\n      <td>0.540</td>\n      <td>45.0</td>\n      <td>815.834</td>\n    </tr>\n    <tr>\n      <th>17</th>\n      <td>2018-01-24</td>\n      <td>1055.25</td>\n      <td>43.476</td>\n      <td>10.167</td>\n      <td>0.973</td>\n      <td>45.0</td>\n      <td>815.834</td>\n    </tr>\n    <tr>\n      <th>18</th>\n      <td>2018-01-25</td>\n      <td>1062.06</td>\n      <td>38.987</td>\n      <td>6.812</td>\n      <td>0.646</td>\n      <td>45.0</td>\n      <td>815.834</td>\n    </tr>\n    <tr>\n      <th>19</th>\n      <td>2018-01-26</td>\n      <td>1060.13</td>\n      <td>31.229</td>\n      <td>-1.932</td>\n      <td>-0.182</td>\n      <td>46.0</td>\n      <td>825.832</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 56
    }
   ],
   "source": [
    "df.head(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\nRangeIndex: 750 entries, 0 to 749\nData columns (total 7 columns):\n #   Column   Non-Null Count  Dtype         \n---  ------   --------------  -----         \n 0   日期       750 non-null    datetime64[ns]\n 1   指数       750 non-null    float64       \n 2   成交额(亿元)  750 non-null    float64       \n 3   涨跌       750 non-null    float64       \n 4   涨跌额      750 non-null    float64       \n 5   转债数目     750 non-null    float64       \n 6   剩余规模     750 non-null    float64       \ndtypes: datetime64[ns](1), float64(6)\nmemory usage: 41.1 KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "            日期       指数  成交额(亿元)      涨跌    涨跌额   转债数目     剩余规模\n",
       "745 2021-01-22  1548.56  463.642  -4.177 -0.269  339.0  5079.33\n",
       "746 2021-01-25  1542.65  534.864  -5.916 -0.382  340.0  5110.36\n",
       "747 2021-01-26  1528.61  435.469 -14.038 -0.910  339.0  5106.60\n",
       "748 2021-01-27  1511.21  487.691 -17.396 -1.138  339.0  5103.05\n",
       "749 2021-01-28  1492.19  492.621 -19.026 -1.259  339.0  5098.99"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>指数</th>\n      <th>成交额(亿元)</th>\n      <th>涨跌</th>\n      <th>涨跌额</th>\n      <th>转债数目</th>\n      <th>剩余规模</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>745</th>\n      <td>2021-01-22</td>\n      <td>1548.56</td>\n      <td>463.642</td>\n      <td>-4.177</td>\n      <td>-0.269</td>\n      <td>339.0</td>\n      <td>5079.33</td>\n    </tr>\n    <tr>\n      <th>746</th>\n      <td>2021-01-25</td>\n      <td>1542.65</td>\n      <td>534.864</td>\n      <td>-5.916</td>\n      <td>-0.382</td>\n      <td>340.0</td>\n      <td>5110.36</td>\n    </tr>\n    <tr>\n      <th>747</th>\n      <td>2021-01-26</td>\n      <td>1528.61</td>\n      <td>435.469</td>\n      <td>-14.038</td>\n      <td>-0.910</td>\n      <td>339.0</td>\n      <td>5106.60</td>\n    </tr>\n    <tr>\n      <th>748</th>\n      <td>2021-01-27</td>\n      <td>1511.21</td>\n      <td>487.691</td>\n      <td>-17.396</td>\n      <td>-1.138</td>\n      <td>339.0</td>\n      <td>5103.05</td>\n    </tr>\n    <tr>\n      <th>749</th>\n      <td>2021-01-28</td>\n      <td>1492.19</td>\n      <td>492.621</td>\n      <td>-19.026</td>\n      <td>-1.259</td>\n      <td>339.0</td>\n      <td>5098.99</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 57
    }
   ],
   "source": [
    "df.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['涨'] = df['涨跌额'].map(lambda x:True if x>=0 else False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "            日期       指数  成交额(亿元)      涨跌    涨跌额   转债数目      剩余规模      涨\n",
       "0   2017-12-29  1000.00   10.581   0.000  0.000   36.0   853.790   True\n",
       "1   2018-01-02  1008.83   13.936   8.831  0.883   36.0   690.602   True\n",
       "2   2018-01-03  1018.81   15.964   9.977  0.989   37.0   691.246   True\n",
       "3   2018-01-04  1024.34   15.495   5.536  0.543   38.0   700.443   True\n",
       "4   2018-01-05  1034.66   19.973  10.311  1.007   38.0   700.443   True\n",
       "..         ...      ...      ...     ...    ...    ...       ...    ...\n",
       "745 2021-01-22  1548.56  463.642  -4.177 -0.269  339.0  5079.330  False\n",
       "746 2021-01-25  1542.65  534.864  -5.916 -0.382  340.0  5110.360  False\n",
       "747 2021-01-26  1528.61  435.469 -14.038 -0.910  339.0  5106.600  False\n",
       "748 2021-01-27  1511.21  487.691 -17.396 -1.138  339.0  5103.050  False\n",
       "749 2021-01-28  1492.19  492.621 -19.026 -1.259  339.0  5098.990  False\n",
       "\n",
       "[750 rows x 8 columns]"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>指数</th>\n      <th>成交额(亿元)</th>\n      <th>涨跌</th>\n      <th>涨跌额</th>\n      <th>转债数目</th>\n      <th>剩余规模</th>\n      <th>涨</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2017-12-29</td>\n      <td>1000.00</td>\n      <td>10.581</td>\n      <td>0.000</td>\n      <td>0.000</td>\n      <td>36.0</td>\n      <td>853.790</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2018-01-02</td>\n      <td>1008.83</td>\n      <td>13.936</td>\n      <td>8.831</td>\n      <td>0.883</td>\n      <td>36.0</td>\n      <td>690.602</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2018-01-03</td>\n      <td>1018.81</td>\n      <td>15.964</td>\n      <td>9.977</td>\n      <td>0.989</td>\n      <td>37.0</td>\n      <td>691.246</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2018-01-04</td>\n      <td>1024.34</td>\n      <td>15.495</td>\n      <td>5.536</td>\n      <td>0.543</td>\n      <td>38.0</td>\n      <td>700.443</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2018-01-05</td>\n      <td>1034.66</td>\n      <td>19.973</td>\n      <td>10.311</td>\n      <td>1.007</td>\n      <td>38.0</td>\n      <td>700.443</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>745</th>\n      <td>2021-01-22</td>\n      <td>1548.56</td>\n      <td>463.642</td>\n      <td>-4.177</td>\n      <td>-0.269</td>\n      <td>339.0</td>\n      <td>5079.330</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>746</th>\n      <td>2021-01-25</td>\n      <td>1542.65</td>\n      <td>534.864</td>\n      <td>-5.916</td>\n      <td>-0.382</td>\n      <td>340.0</td>\n      <td>5110.360</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>747</th>\n      <td>2021-01-26</td>\n      <td>1528.61</td>\n      <td>435.469</td>\n      <td>-14.038</td>\n      <td>-0.910</td>\n      <td>339.0</td>\n      <td>5106.600</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>748</th>\n      <td>2021-01-27</td>\n      <td>1511.21</td>\n      <td>487.691</td>\n      <td>-17.396</td>\n      <td>-1.138</td>\n      <td>339.0</td>\n      <td>5103.050</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>749</th>\n      <td>2021-01-28</td>\n      <td>1492.19</td>\n      <td>492.621</td>\n      <td>-19.026</td>\n      <td>-1.259</td>\n      <td>339.0</td>\n      <td>5098.990</td>\n      <td>False</td>\n    </tr>\n  </tbody>\n</table>\n<p>750 rows × 8 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 24
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['日期']=pd.to_datetime(df['日期'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [],
   "source": [
    "df=df.set_index('日期',drop=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "                   日期       指数  成交额(亿元)      涨跌    涨跌额   转债数目     剩余规模\n",
       "日期                                                                    \n",
       "2019-06-14 2019-06-14  1089.07   49.941  -7.882 -0.719  160.0  2645.36\n",
       "2019-06-17 2019-06-17  1087.09   44.379  -1.979 -0.182  159.0  2633.41\n",
       "2019-06-18 2019-06-18  1086.46   50.812  -0.630 -0.058  160.0  2650.74\n",
       "2019-06-19 2019-06-19  1093.36   58.761   6.898  0.635  160.0  2650.74\n",
       "2019-06-20 2019-06-20  1106.05   81.703  12.691  1.161  160.0  2650.74\n",
       "2019-06-21 2019-06-21  1116.92   62.145  10.867  0.983  160.0  2650.74\n",
       "2019-06-24 2019-06-24  1116.27   44.539  -0.649 -0.058  160.0  2651.52\n",
       "2019-06-25 2019-06-25  1111.02   51.233  -5.250 -0.470  161.0  2653.44\n",
       "2019-06-26 2019-06-26  1114.55   40.451   3.529  0.318  161.0  2653.44\n",
       "2019-06-27 2019-06-27  1121.20   74.966   6.649  0.597  162.0  2664.61\n",
       "2019-06-28 2019-06-28  1121.08   46.615  -0.119 -0.011  162.0  2664.61\n",
       "2019-07-01 2019-07-01  1138.60   89.704  17.517  1.563  162.0  2664.61\n",
       "2019-07-02 2019-07-02  1138.09   86.956  -0.508 -0.045  164.0  2672.98\n",
       "2019-07-03 2019-07-03  1133.57   74.089  -4.520 -0.397  164.0  2672.98\n",
       "2019-07-04 2019-07-04  1133.31   82.674  -0.261 -0.023  164.0  2672.98\n",
       "2019-07-05 2019-07-05  1132.87   64.786  -0.441 -0.039  164.0  2676.34\n",
       "2019-07-08 2019-07-08  1119.73   49.261 -13.137 -1.160  165.0  2684.34\n",
       "2019-07-09 2019-07-09  1119.09   46.949  -0.643 -0.057  166.0  2706.04\n",
       "2019-07-10 2019-07-10  1116.22   40.163  -2.866 -0.256  166.0  2706.04\n",
       "2019-07-11 2019-07-11  1116.06   41.757  -0.164 -0.015  167.0  2712.44"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>指数</th>\n      <th>成交额(亿元)</th>\n      <th>涨跌</th>\n      <th>涨跌额</th>\n      <th>转债数目</th>\n      <th>剩余规模</th>\n    </tr>\n    <tr>\n      <th>日期</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2019-06-14</th>\n      <td>2019-06-14</td>\n      <td>1089.07</td>\n      <td>49.941</td>\n      <td>-7.882</td>\n      <td>-0.719</td>\n      <td>160.0</td>\n      <td>2645.36</td>\n    </tr>\n    <tr>\n      <th>2019-06-17</th>\n      <td>2019-06-17</td>\n      <td>1087.09</td>\n      <td>44.379</td>\n      <td>-1.979</td>\n      <td>-0.182</td>\n      <td>159.0</td>\n      <td>2633.41</td>\n    </tr>\n    <tr>\n      <th>2019-06-18</th>\n      <td>2019-06-18</td>\n      <td>1086.46</td>\n      <td>50.812</td>\n      <td>-0.630</td>\n      <td>-0.058</td>\n      <td>160.0</td>\n      <td>2650.74</td>\n    </tr>\n    <tr>\n      <th>2019-06-19</th>\n      <td>2019-06-19</td>\n      <td>1093.36</td>\n      <td>58.761</td>\n      <td>6.898</td>\n      <td>0.635</td>\n      <td>160.0</td>\n      <td>2650.74</td>\n    </tr>\n    <tr>\n      <th>2019-06-20</th>\n      <td>2019-06-20</td>\n      <td>1106.05</td>\n      <td>81.703</td>\n      <td>12.691</td>\n      <td>1.161</td>\n      <td>160.0</td>\n      <td>2650.74</td>\n    </tr>\n    <tr>\n      <th>2019-06-21</th>\n      <td>2019-06-21</td>\n      <td>1116.92</td>\n      <td>62.145</td>\n      <td>10.867</td>\n      <td>0.983</td>\n      <td>160.0</td>\n      <td>2650.74</td>\n    </tr>\n    <tr>\n      <th>2019-06-24</th>\n      <td>2019-06-24</td>\n      <td>1116.27</td>\n      <td>44.539</td>\n      <td>-0.649</td>\n      <td>-0.058</td>\n      <td>160.0</td>\n      <td>2651.52</td>\n    </tr>\n    <tr>\n      <th>2019-06-25</th>\n      <td>2019-06-25</td>\n      <td>1111.02</td>\n      <td>51.233</td>\n      <td>-5.250</td>\n      <td>-0.470</td>\n      <td>161.0</td>\n      <td>2653.44</td>\n    </tr>\n    <tr>\n      <th>2019-06-26</th>\n      <td>2019-06-26</td>\n      <td>1114.55</td>\n      <td>40.451</td>\n      <td>3.529</td>\n      <td>0.318</td>\n      <td>161.0</td>\n      <td>2653.44</td>\n    </tr>\n    <tr>\n      <th>2019-06-27</th>\n      <td>2019-06-27</td>\n      <td>1121.20</td>\n      <td>74.966</td>\n      <td>6.649</td>\n      <td>0.597</td>\n      <td>162.0</td>\n      <td>2664.61</td>\n    </tr>\n    <tr>\n      <th>2019-06-28</th>\n      <td>2019-06-28</td>\n      <td>1121.08</td>\n      <td>46.615</td>\n      <td>-0.119</td>\n      <td>-0.011</td>\n      <td>162.0</td>\n      <td>2664.61</td>\n    </tr>\n    <tr>\n      <th>2019-07-01</th>\n      <td>2019-07-01</td>\n      <td>1138.60</td>\n      <td>89.704</td>\n      <td>17.517</td>\n      <td>1.563</td>\n      <td>162.0</td>\n      <td>2664.61</td>\n    </tr>\n    <tr>\n      <th>2019-07-02</th>\n      <td>2019-07-02</td>\n      <td>1138.09</td>\n      <td>86.956</td>\n      <td>-0.508</td>\n      <td>-0.045</td>\n      <td>164.0</td>\n      <td>2672.98</td>\n    </tr>\n    <tr>\n      <th>2019-07-03</th>\n      <td>2019-07-03</td>\n      <td>1133.57</td>\n      <td>74.089</td>\n      <td>-4.520</td>\n      <td>-0.397</td>\n      <td>164.0</td>\n      <td>2672.98</td>\n    </tr>\n    <tr>\n      <th>2019-07-04</th>\n      <td>2019-07-04</td>\n      <td>1133.31</td>\n      <td>82.674</td>\n      <td>-0.261</td>\n      <td>-0.023</td>\n      <td>164.0</td>\n      <td>2672.98</td>\n    </tr>\n    <tr>\n      <th>2019-07-05</th>\n      <td>2019-07-05</td>\n      <td>1132.87</td>\n      <td>64.786</td>\n      <td>-0.441</td>\n      <td>-0.039</td>\n      <td>164.0</td>\n      <td>2676.34</td>\n    </tr>\n    <tr>\n      <th>2019-07-08</th>\n      <td>2019-07-08</td>\n      <td>1119.73</td>\n      <td>49.261</td>\n      <td>-13.137</td>\n      <td>-1.160</td>\n      <td>165.0</td>\n      <td>2684.34</td>\n    </tr>\n    <tr>\n      <th>2019-07-09</th>\n      <td>2019-07-09</td>\n      <td>1119.09</td>\n      <td>46.949</td>\n      <td>-0.643</td>\n      <td>-0.057</td>\n      <td>166.0</td>\n      <td>2706.04</td>\n    </tr>\n    <tr>\n      <th>2019-07-10</th>\n      <td>2019-07-10</td>\n      <td>1116.22</td>\n      <td>40.163</td>\n      <td>-2.866</td>\n      <td>-0.256</td>\n      <td>166.0</td>\n      <td>2706.04</td>\n    </tr>\n    <tr>\n      <th>2019-07-11</th>\n      <td>2019-07-11</td>\n      <td>1116.06</td>\n      <td>41.757</td>\n      <td>-0.164</td>\n      <td>-0.015</td>\n      <td>167.0</td>\n      <td>2712.44</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 81
    }
   ],
   "source": [
    "df[df['日期']<'2019-07-12'].tail(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [],
   "source": [
    "max_day = 0\n",
    "max_day_list =[]\n",
    "for index,row in df.iterrows():\n",
    "    if row['涨跌额'] <0:\n",
    "        max_day+=1\n",
    "    else:\n",
    "        max_day_list.append((index,max_day))     \n",
    "        max_day=0\n",
    "\n",
    "if max_day!=0:\n",
    "    max_day_list.append((index,max_day))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "[(Timestamp('2017-12-29 00:00:00'), 0),\n",
       " (Timestamp('2018-01-02 00:00:00'), 0),\n",
       " (Timestamp('2018-01-03 00:00:00'), 0),\n",
       " (Timestamp('2018-01-04 00:00:00'), 0),\n",
       " (Timestamp('2018-01-05 00:00:00'), 0),\n",
       " (Timestamp('2018-01-08 00:00:00'), 0),\n",
       " (Timestamp('2018-01-11 00:00:00'), 2),\n",
       " (Timestamp('2018-01-16 00:00:00'), 2),\n",
       " (Timestamp('2018-01-18 00:00:00'), 1),\n",
       " (Timestamp('2018-01-19 00:00:00'), 0),\n",
       " (Timestamp('2018-01-22 00:00:00'), 0),\n",
       " (Timestamp('2018-01-23 00:00:00'), 0),\n",
       " (Timestamp('2018-01-24 00:00:00'), 0),\n",
       " (Timestamp('2018-01-25 00:00:00'), 0),\n",
       " (Timestamp('2018-02-02 00:00:00'), 5),\n",
       " (Timestamp('2018-02-05 00:00:00'), 0),\n",
       " (Timestamp('2018-02-12 00:00:00'), 4),\n",
       " (Timestamp('2018-02-13 00:00:00'), 0),\n",
       " (Timestamp('2018-02-14 00:00:00'), 0),\n",
       " (Timestamp('2018-02-22 00:00:00'), 0),\n",
       " (Timestamp('2018-02-26 00:00:00'), 1),\n",
       " (Timestamp('2018-03-01 00:00:00'), 2),\n",
       " (Timestamp('2018-03-06 00:00:00'), 2),\n",
       " (Timestamp('2018-03-08 00:00:00'), 1),\n",
       " (Timestamp('2018-03-09 00:00:00'), 0),\n",
       " (Timestamp('2018-03-12 00:00:00'), 0),\n",
       " (Timestamp('2018-03-19 00:00:00'), 4),\n",
       " (Timestamp('2018-03-26 00:00:00'), 4),\n",
       " (Timestamp('2018-03-27 00:00:00'), 0),\n",
       " (Timestamp('2018-03-29 00:00:00'), 1),\n",
       " (Timestamp('2018-03-30 00:00:00'), 0),\n",
       " (Timestamp('2018-04-02 00:00:00'), 0),\n",
       " (Timestamp('2018-04-09 00:00:00'), 2),\n",
       " (Timestamp('2018-04-11 00:00:00'), 1),\n",
       " (Timestamp('2018-04-18 00:00:00'), 4),\n",
       " (Timestamp('2018-04-19 00:00:00'), 0),\n",
       " (Timestamp('2018-04-24 00:00:00'), 2),\n",
       " (Timestamp('2018-04-27 00:00:00'), 2),\n",
       " (Timestamp('2018-05-03 00:00:00'), 1),\n",
       " (Timestamp('2018-05-04 00:00:00'), 0),\n",
       " (Timestamp('2018-05-07 00:00:00'), 0),\n",
       " (Timestamp('2018-05-08 00:00:00'), 0),\n",
       " (Timestamp('2018-05-10 00:00:00'), 1),\n",
       " (Timestamp('2018-05-15 00:00:00'), 2),\n",
       " (Timestamp('2018-05-18 00:00:00'), 2),\n",
       " (Timestamp('2018-05-21 00:00:00'), 0),\n",
       " (Timestamp('2018-05-22 00:00:00'), 0),\n",
       " (Timestamp('2018-05-31 00:00:00'), 6),\n",
       " (Timestamp('2018-06-05 00:00:00'), 2),\n",
       " (Timestamp('2018-06-06 00:00:00'), 0),\n",
       " (Timestamp('2018-06-07 00:00:00'), 0),\n",
       " (Timestamp('2018-06-12 00:00:00'), 2),\n",
       " (Timestamp('2018-06-20 00:00:00'), 4),\n",
       " (Timestamp('2018-06-22 00:00:00'), 1),\n",
       " (Timestamp('2018-06-25 00:00:00'), 0),\n",
       " (Timestamp('2018-06-26 00:00:00'), 0),\n",
       " (Timestamp('2018-06-28 00:00:00'), 1),\n",
       " (Timestamp('2018-06-29 00:00:00'), 0),\n",
       " (Timestamp('2018-07-03 00:00:00'), 1),\n",
       " (Timestamp('2018-07-06 00:00:00'), 2),\n",
       " (Timestamp('2018-07-09 00:00:00'), 0),\n",
       " (Timestamp('2018-07-10 00:00:00'), 0),\n",
       " (Timestamp('2018-07-12 00:00:00'), 1),\n",
       " (Timestamp('2018-07-13 00:00:00'), 0),\n",
       " (Timestamp('2018-07-17 00:00:00'), 1),\n",
       " (Timestamp('2018-07-18 00:00:00'), 0),\n",
       " (Timestamp('2018-07-19 00:00:00'), 0),\n",
       " (Timestamp('2018-07-20 00:00:00'), 0),\n",
       " (Timestamp('2018-07-23 00:00:00'), 0),\n",
       " (Timestamp('2018-07-24 00:00:00'), 0),\n",
       " (Timestamp('2018-07-31 00:00:00'), 4),\n",
       " (Timestamp('2018-08-07 00:00:00'), 4),\n",
       " (Timestamp('2018-08-09 00:00:00'), 1),\n",
       " (Timestamp('2018-08-10 00:00:00'), 0),\n",
       " (Timestamp('2018-08-13 00:00:00'), 0),\n",
       " (Timestamp('2018-08-21 00:00:00'), 5),\n",
       " (Timestamp('2018-08-23 00:00:00'), 1),\n",
       " (Timestamp('2018-08-24 00:00:00'), 0),\n",
       " (Timestamp('2018-08-27 00:00:00'), 0),\n",
       " (Timestamp('2018-08-28 00:00:00'), 0),\n",
       " (Timestamp('2018-09-04 00:00:00'), 4),\n",
       " (Timestamp('2018-09-13 00:00:00'), 6),\n",
       " (Timestamp('2018-09-18 00:00:00'), 2),\n",
       " (Timestamp('2018-09-19 00:00:00'), 0),\n",
       " (Timestamp('2018-09-21 00:00:00'), 1),\n",
       " (Timestamp('2018-09-26 00:00:00'), 1),\n",
       " (Timestamp('2018-09-28 00:00:00'), 1),\n",
       " (Timestamp('2018-10-12 00:00:00'), 4),\n",
       " (Timestamp('2018-10-19 00:00:00'), 4),\n",
       " (Timestamp('2018-10-22 00:00:00'), 0),\n",
       " (Timestamp('2018-10-24 00:00:00'), 1),\n",
       " (Timestamp('2018-10-26 00:00:00'), 1),\n",
       " (Timestamp('2018-10-30 00:00:00'), 1),\n",
       " (Timestamp('2018-10-31 00:00:00'), 0),\n",
       " (Timestamp('2018-11-01 00:00:00'), 0),\n",
       " (Timestamp('2018-11-02 00:00:00'), 0),\n",
       " (Timestamp('2018-11-05 00:00:00'), 0),\n",
       " (Timestamp('2018-11-07 00:00:00'), 1),\n",
       " (Timestamp('2018-11-12 00:00:00'), 2),\n",
       " (Timestamp('2018-11-13 00:00:00'), 0),\n",
       " (Timestamp('2018-11-14 00:00:00'), 0),\n",
       " (Timestamp('2018-11-15 00:00:00'), 0),\n",
       " (Timestamp('2018-11-16 00:00:00'), 0),\n",
       " (Timestamp('2018-11-19 00:00:00'), 0),\n",
       " (Timestamp('2018-11-21 00:00:00'), 1),\n",
       " (Timestamp('2018-11-27 00:00:00'), 3),\n",
       " (Timestamp('2018-11-28 00:00:00'), 0),\n",
       " (Timestamp('2018-11-30 00:00:00'), 1),\n",
       " (Timestamp('2018-12-03 00:00:00'), 0),\n",
       " (Timestamp('2018-12-04 00:00:00'), 0),\n",
       " (Timestamp('2018-12-05 00:00:00'), 0),\n",
       " (Timestamp('2018-12-07 00:00:00'), 1),\n",
       " (Timestamp('2018-12-12 00:00:00'), 2),\n",
       " (Timestamp('2018-12-13 00:00:00'), 0),\n",
       " (Timestamp('2018-12-24 00:00:00'), 6),\n",
       " (Timestamp('2018-12-28 00:00:00'), 3),\n",
       " (Timestamp('2019-01-03 00:00:00'), 1),\n",
       " (Timestamp('2019-01-04 00:00:00'), 0),\n",
       " (Timestamp('2019-01-07 00:00:00'), 0),\n",
       " (Timestamp('2019-01-08 00:00:00'), 0),\n",
       " (Timestamp('2019-01-09 00:00:00'), 0),\n",
       " (Timestamp('2019-01-10 00:00:00'), 0),\n",
       " (Timestamp('2019-01-11 00:00:00'), 0),\n",
       " (Timestamp('2019-01-15 00:00:00'), 1),\n",
       " (Timestamp('2019-01-16 00:00:00'), 0),\n",
       " (Timestamp('2019-01-18 00:00:00'), 1),\n",
       " (Timestamp('2019-01-21 00:00:00'), 0),\n",
       " (Timestamp('2019-01-23 00:00:00'), 1),\n",
       " (Timestamp('2019-01-24 00:00:00'), 0),\n",
       " (Timestamp('2019-01-25 00:00:00'), 0),\n",
       " (Timestamp('2019-02-01 00:00:00'), 4),\n",
       " (Timestamp('2019-02-11 00:00:00'), 0),\n",
       " (Timestamp('2019-02-12 00:00:00'), 0),\n",
       " (Timestamp('2019-02-13 00:00:00'), 0),\n",
       " (Timestamp('2019-02-14 00:00:00'), 0),\n",
       " (Timestamp('2019-02-18 00:00:00'), 1),\n",
       " (Timestamp('2019-02-20 00:00:00'), 1),\n",
       " (Timestamp('2019-02-21 00:00:00'), 0),\n",
       " (Timestamp('2019-02-22 00:00:00'), 0),\n",
       " (Timestamp('2019-02-25 00:00:00'), 0),\n",
       " (Timestamp('2019-02-28 00:00:00'), 2),\n",
       " (Timestamp('2019-03-01 00:00:00'), 0),\n",
       " (Timestamp('2019-03-04 00:00:00'), 0),\n",
       " (Timestamp('2019-03-05 00:00:00'), 0),\n",
       " (Timestamp('2019-03-06 00:00:00'), 0),\n",
       " (Timestamp('2019-03-07 00:00:00'), 0),\n",
       " (Timestamp('2019-03-11 00:00:00'), 1),\n",
       " (Timestamp('2019-03-12 00:00:00'), 0),\n",
       " (Timestamp('2019-03-15 00:00:00'), 2),\n",
       " (Timestamp('2019-03-18 00:00:00'), 0),\n",
       " (Timestamp('2019-03-19 00:00:00'), 0),\n",
       " (Timestamp('2019-03-21 00:00:00'), 1),\n",
       " (Timestamp('2019-03-27 00:00:00'), 3),\n",
       " (Timestamp('2019-03-29 00:00:00'), 1),\n",
       " (Timestamp('2019-04-01 00:00:00'), 0),\n",
       " (Timestamp('2019-04-02 00:00:00'), 0),\n",
       " (Timestamp('2019-04-03 00:00:00'), 0),\n",
       " (Timestamp('2019-04-04 00:00:00'), 0),\n",
       " (Timestamp('2019-04-12 00:00:00'), 4),\n",
       " (Timestamp('2019-04-16 00:00:00'), 1),\n",
       " (Timestamp('2019-04-17 00:00:00'), 0),\n",
       " (Timestamp('2019-04-19 00:00:00'), 1),\n",
       " (Timestamp('2019-04-30 00:00:00'), 6),\n",
       " (Timestamp('2019-05-07 00:00:00'), 1),\n",
       " (Timestamp('2019-05-08 00:00:00'), 0),\n",
       " (Timestamp('2019-05-09 00:00:00'), 0),\n",
       " (Timestamp('2019-05-10 00:00:00'), 0),\n",
       " (Timestamp('2019-05-14 00:00:00'), 1),\n",
       " (Timestamp('2019-05-15 00:00:00'), 0),\n",
       " (Timestamp('2019-05-16 00:00:00'), 0),\n",
       " (Timestamp('2019-05-21 00:00:00'), 2),\n",
       " (Timestamp('2019-05-27 00:00:00'), 3),\n",
       " (Timestamp('2019-05-28 00:00:00'), 0),\n",
       " (Timestamp('2019-05-29 00:00:00'), 0),\n",
       " (Timestamp('2019-06-10 00:00:00'), 6),\n",
       " (Timestamp('2019-06-11 00:00:00'), 0),\n",
       " (Timestamp('2019-06-13 00:00:00'), 1),\n",
       " (Timestamp('2019-06-19 00:00:00'), 3),\n",
       " (Timestamp('2019-06-20 00:00:00'), 0),\n",
       " (Timestamp('2019-06-21 00:00:00'), 0),\n",
       " (Timestamp('2019-06-26 00:00:00'), 2),\n",
       " (Timestamp('2019-06-27 00:00:00'), 0),\n",
       " (Timestamp('2019-07-01 00:00:00'), 1),\n",
       " (Timestamp('2019-07-12 00:00:00'), 8),\n",
       " (Timestamp('2019-07-15 00:00:00'), 0),\n",
       " (Timestamp('2019-07-16 00:00:00'), 0),\n",
       " (Timestamp('2019-07-17 00:00:00'), 0),\n",
       " (Timestamp('2019-07-19 00:00:00'), 1),\n",
       " (Timestamp('2019-07-23 00:00:00'), 1),\n",
       " (Timestamp('2019-07-24 00:00:00'), 0),\n",
       " (Timestamp('2019-07-25 00:00:00'), 0),\n",
       " (Timestamp('2019-07-26 00:00:00'), 0),\n",
       " (Timestamp('2019-07-29 00:00:00'), 0),\n",
       " (Timestamp('2019-07-30 00:00:00'), 0),\n",
       " (Timestamp('2019-07-31 00:00:00'), 0),\n",
       " (Timestamp('2019-08-07 00:00:00'), 4),\n",
       " (Timestamp('2019-08-08 00:00:00'), 0),\n",
       " (Timestamp('2019-08-12 00:00:00'), 1),\n",
       " (Timestamp('2019-08-14 00:00:00'), 1),\n",
       " (Timestamp('2019-08-15 00:00:00'), 0),\n",
       " (Timestamp('2019-08-16 00:00:00'), 0),\n",
       " (Timestamp('2019-08-19 00:00:00'), 0),\n",
       " (Timestamp('2019-08-20 00:00:00'), 0),\n",
       " (Timestamp('2019-08-21 00:00:00'), 0),\n",
       " (Timestamp('2019-08-23 00:00:00'), 1),\n",
       " (Timestamp('2019-08-27 00:00:00'), 1),\n",
       " (Timestamp('2019-08-28 00:00:00'), 0),\n",
       " (Timestamp('2019-09-02 00:00:00'), 2),\n",
       " (Timestamp('2019-09-03 00:00:00'), 0),\n",
       " (Timestamp('2019-09-04 00:00:00'), 0),\n",
       " (Timestamp('2019-09-05 00:00:00'), 0),\n",
       " (Timestamp('2019-09-06 00:00:00'), 0),\n",
       " (Timestamp('2019-09-09 00:00:00'), 0),\n",
       " (Timestamp('2019-09-10 00:00:00'), 0),\n",
       " (Timestamp('2019-09-12 00:00:00'), 1),\n",
       " (Timestamp('2019-09-18 00:00:00'), 2),\n",
       " (Timestamp('2019-09-19 00:00:00'), 0),\n",
       " (Timestamp('2019-09-20 00:00:00'), 0),\n",
       " (Timestamp('2019-09-24 00:00:00'), 1),\n",
       " (Timestamp('2019-09-27 00:00:00'), 2),\n",
       " (Timestamp('2019-10-09 00:00:00'), 2),\n",
       " (Timestamp('2019-10-10 00:00:00'), 0),\n",
       " (Timestamp('2019-10-11 00:00:00'), 0),\n",
       " (Timestamp('2019-10-14 00:00:00'), 0),\n",
       " (Timestamp('2019-10-22 00:00:00'), 5),\n",
       " (Timestamp('2019-10-25 00:00:00'), 2),\n",
       " (Timestamp('2019-10-28 00:00:00'), 0),\n",
       " (Timestamp('2019-11-01 00:00:00'), 3),\n",
       " (Timestamp('2019-11-04 00:00:00'), 0),\n",
       " (Timestamp('2019-11-05 00:00:00'), 0),\n",
       " (Timestamp('2019-11-07 00:00:00'), 1),\n",
       " (Timestamp('2019-11-14 00:00:00'), 4),\n",
       " (Timestamp('2019-11-18 00:00:00'), 1),\n",
       " (Timestamp('2019-11-19 00:00:00'), 0),\n",
       " (Timestamp('2019-11-26 00:00:00'), 4),\n",
       " (Timestamp('2019-12-03 00:00:00'), 4),\n",
       " (Timestamp('2019-12-04 00:00:00'), 0),\n",
       " (Timestamp('2019-12-05 00:00:00'), 0),\n",
       " (Timestamp('2019-12-06 00:00:00'), 0),\n",
       " (Timestamp('2019-12-09 00:00:00'), 0),\n",
       " (Timestamp('2019-12-10 00:00:00'), 0),\n",
       " (Timestamp('2019-12-11 00:00:00'), 0),\n",
       " (Timestamp('2019-12-12 00:00:00'), 0),\n",
       " (Timestamp('2019-12-13 00:00:00'), 0),\n",
       " (Timestamp('2019-12-16 00:00:00'), 0),\n",
       " (Timestamp('2019-12-17 00:00:00'), 0),\n",
       " (Timestamp('2019-12-18 00:00:00'), 0),\n",
       " (Timestamp('2019-12-24 00:00:00'), 3),\n",
       " (Timestamp('2019-12-25 00:00:00'), 0),\n",
       " (Timestamp('2019-12-26 00:00:00'), 0),\n",
       " (Timestamp('2019-12-30 00:00:00'), 1),\n",
       " (Timestamp('2019-12-31 00:00:00'), 0),\n",
       " (Timestamp('2020-01-02 00:00:00'), 0),\n",
       " (Timestamp('2020-01-03 00:00:00'), 0),\n",
       " (Timestamp('2020-01-06 00:00:00'), 0),\n",
       " (Timestamp('2020-01-07 00:00:00'), 0),\n",
       " (Timestamp('2020-01-09 00:00:00'), 1),\n",
       " (Timestamp('2020-01-13 00:00:00'), 1),\n",
       " (Timestamp('2020-01-14 00:00:00'), 0),\n",
       " (Timestamp('2020-01-17 00:00:00'), 2),\n",
       " (Timestamp('2020-01-20 00:00:00'), 0),\n",
       " (Timestamp('2020-01-22 00:00:00'), 1),\n",
       " (Timestamp('2020-02-04 00:00:00'), 2),\n",
       " (Timestamp('2020-02-05 00:00:00'), 0),\n",
       " (Timestamp('2020-02-06 00:00:00'), 0),\n",
       " (Timestamp('2020-02-10 00:00:00'), 1),\n",
       " (Timestamp('2020-02-11 00:00:00'), 0),\n",
       " (Timestamp('2020-02-12 00:00:00'), 0),\n",
       " (Timestamp('2020-02-14 00:00:00'), 1),\n",
       " (Timestamp('2020-02-17 00:00:00'), 0),\n",
       " (Timestamp('2020-02-18 00:00:00'), 0),\n",
       " (Timestamp('2020-02-19 00:00:00'), 0),\n",
       " (Timestamp('2020-02-20 00:00:00'), 0),\n",
       " (Timestamp('2020-02-21 00:00:00'), 0),\n",
       " (Timestamp('2020-02-24 00:00:00'), 0),\n",
       " (Timestamp('2020-03-02 00:00:00'), 4),\n",
       " (Timestamp('2020-03-03 00:00:00'), 0),\n",
       " (Timestamp('2020-03-04 00:00:00'), 0),\n",
       " (Timestamp('2020-03-05 00:00:00'), 0),\n",
       " (Timestamp('2020-03-06 00:00:00'), 0),\n",
       " (Timestamp('2020-03-10 00:00:00'), 1),\n",
       " (Timestamp('2020-03-11 00:00:00'), 0),\n",
       " (Timestamp('2020-03-17 00:00:00'), 3),\n",
       " (Timestamp('2020-03-18 00:00:00'), 0),\n",
       " (Timestamp('2020-03-19 00:00:00'), 0),\n",
       " (Timestamp('2020-03-20 00:00:00'), 0),\n",
       " (Timestamp('2020-03-24 00:00:00'), 1),\n",
       " (Timestamp('2020-03-25 00:00:00'), 0),\n",
       " (Timestamp('2020-03-31 00:00:00'), 3),\n",
       " (Timestamp('2020-04-01 00:00:00'), 0),\n",
       " (Timestamp('2020-04-07 00:00:00'), 2),\n",
       " (Timestamp('2020-04-14 00:00:00'), 4),\n",
       " (Timestamp('2020-04-15 00:00:00'), 0),\n",
       " (Timestamp('2020-04-16 00:00:00'), 0),\n",
       " (Timestamp('2020-04-17 00:00:00'), 0),\n",
       " (Timestamp('2020-04-20 00:00:00'), 0),\n",
       " (Timestamp('2020-04-21 00:00:00'), 0),\n",
       " (Timestamp('2020-04-22 00:00:00'), 0),\n",
       " (Timestamp('2020-04-23 00:00:00'), 0),\n",
       " (Timestamp('2020-04-27 00:00:00'), 1),\n",
       " (Timestamp('2020-04-30 00:00:00'), 2),\n",
       " (Timestamp('2020-05-06 00:00:00'), 0),\n",
       " (Timestamp('2020-05-08 00:00:00'), 1),\n",
       " (Timestamp('2020-05-11 00:00:00'), 0),\n",
       " (Timestamp('2020-05-19 00:00:00'), 5),\n",
       " (Timestamp('2020-05-26 00:00:00'), 4),\n",
       " (Timestamp('2020-05-27 00:00:00'), 0),\n",
       " (Timestamp('2020-05-29 00:00:00'), 1),\n",
       " (Timestamp('2020-06-01 00:00:00'), 0),\n",
       " (Timestamp('2020-06-02 00:00:00'), 0),\n",
       " (Timestamp('2020-06-08 00:00:00'), 3),\n",
       " (Timestamp('2020-06-09 00:00:00'), 0),\n",
       " (Timestamp('2020-06-12 00:00:00'), 2),\n",
       " (Timestamp('2020-06-15 00:00:00'), 0),\n",
       " (Timestamp('2020-06-16 00:00:00'), 0),\n",
       " (Timestamp('2020-06-17 00:00:00'), 0),\n",
       " (Timestamp('2020-06-18 00:00:00'), 0),\n",
       " (Timestamp('2020-06-19 00:00:00'), 0),\n",
       " (Timestamp('2020-06-30 00:00:00'), 4),\n",
       " (Timestamp('2020-07-01 00:00:00'), 0),\n",
       " (Timestamp('2020-07-02 00:00:00'), 0),\n",
       " (Timestamp('2020-07-03 00:00:00'), 0),\n",
       " (Timestamp('2020-07-06 00:00:00'), 0),\n",
       " (Timestamp('2020-07-07 00:00:00'), 0),\n",
       " (Timestamp('2020-07-08 00:00:00'), 0),\n",
       " (Timestamp('2020-07-09 00:00:00'), 0),\n",
       " (Timestamp('2020-07-13 00:00:00'), 1),\n",
       " (Timestamp('2020-07-17 00:00:00'), 3),\n",
       " (Timestamp('2020-07-20 00:00:00'), 0),\n",
       " (Timestamp('2020-07-21 00:00:00'), 0),\n",
       " (Timestamp('2020-07-22 00:00:00'), 0),\n",
       " (Timestamp('2020-07-23 00:00:00'), 0),\n",
       " (Timestamp('2020-07-28 00:00:00'), 2),\n",
       " (Timestamp('2020-07-29 00:00:00'), 0),\n",
       " (Timestamp('2020-07-30 00:00:00'), 0),\n",
       " (Timestamp('2020-07-31 00:00:00'), 0),\n",
       " (Timestamp('2020-08-03 00:00:00'), 0),\n",
       " (Timestamp('2020-08-05 00:00:00'), 1),\n",
       " (Timestamp('2020-08-10 00:00:00'), 2),\n",
       " (Timestamp('2020-08-13 00:00:00'), 2),\n",
       " (Timestamp('2020-08-17 00:00:00'), 1),\n",
       " (Timestamp('2020-08-18 00:00:00'), 0),\n",
       " (Timestamp('2020-08-21 00:00:00'), 2),\n",
       " (Timestamp('2020-08-25 00:00:00'), 1),\n",
       " (Timestamp('2020-08-27 00:00:00'), 1),\n",
       " (Timestamp('2020-08-28 00:00:00'), 0),\n",
       " (Timestamp('2020-08-31 00:00:00'), 0),\n",
       " (Timestamp('2020-09-01 00:00:00'), 0),\n",
       " (Timestamp('2020-09-02 00:00:00'), 0),\n",
       " (Timestamp('2020-09-11 00:00:00'), 6),\n",
       " (Timestamp('2020-09-14 00:00:00'), 0),\n",
       " (Timestamp('2020-09-15 00:00:00'), 0),\n",
       " (Timestamp('2020-09-17 00:00:00'), 1),\n",
       " (Timestamp('2020-09-18 00:00:00'), 0),\n",
       " (Timestamp('2020-09-29 00:00:00'), 6),\n",
       " (Timestamp('2020-09-30 00:00:00'), 0),\n",
       " (Timestamp('2020-10-09 00:00:00'), 0),\n",
       " (Timestamp('2020-10-12 00:00:00'), 0),\n",
       " (Timestamp('2020-10-13 00:00:00'), 0),\n",
       " (Timestamp('2020-10-19 00:00:00'), 3),\n",
       " (Timestamp('2020-10-20 00:00:00'), 0),\n",
       " (Timestamp('2020-10-21 00:00:00'), 0),\n",
       " (Timestamp('2020-10-22 00:00:00'), 0),\n",
       " (Timestamp('2020-10-26 00:00:00'), 1),\n",
       " (Timestamp('2020-10-27 00:00:00'), 0),\n",
       " (Timestamp('2020-11-04 00:00:00'), 5),\n",
       " (Timestamp('2020-11-05 00:00:00'), 0),\n",
       " (Timestamp('2020-11-09 00:00:00'), 1),\n",
       " (Timestamp('2020-11-12 00:00:00'), 2),\n",
       " (Timestamp('2020-11-13 00:00:00'), 0),\n",
       " (Timestamp('2020-11-20 00:00:00'), 4),\n",
       " (Timestamp('2020-11-23 00:00:00'), 0),\n",
       " (Timestamp('2020-11-24 00:00:00'), 0),\n",
       " (Timestamp('2020-11-30 00:00:00'), 3),\n",
       " (Timestamp('2020-12-01 00:00:00'), 0),\n",
       " (Timestamp('2020-12-04 00:00:00'), 2),\n",
       " (Timestamp('2020-12-07 00:00:00'), 0),\n",
       " (Timestamp('2020-12-10 00:00:00'), 2),\n",
       " (Timestamp('2020-12-17 00:00:00'), 4),\n",
       " (Timestamp('2020-12-18 00:00:00'), 0),\n",
       " (Timestamp('2020-12-21 00:00:00'), 0),\n",
       " (Timestamp('2020-12-25 00:00:00'), 3),\n",
       " (Timestamp('2020-12-30 00:00:00'), 2),\n",
       " (Timestamp('2020-12-31 00:00:00'), 0),\n",
       " (Timestamp('2021-01-04 00:00:00'), 0),\n",
       " (Timestamp('2021-01-05 00:00:00'), 0),\n",
       " (Timestamp('2021-01-12 00:00:00'), 4),\n",
       " (Timestamp('2021-01-14 00:00:00'), 1),\n",
       " (Timestamp('2021-01-15 00:00:00'), 0),\n",
       " (Timestamp('2021-01-18 00:00:00'), 0),\n",
       " (Timestamp('2021-01-20 00:00:00'), 1),\n",
       " (Timestamp('2021-01-21 00:00:00'), 0)]"
      ]
     },
     "metadata": {},
     "execution_count": 83
    }
   ],
   "source": [
    "max_day_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "result = list(sorted(max_day_list,key=lambda x:x[1],reverse=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "[(Timestamp('2019-07-12 00:00:00'), 8),\n",
       " (Timestamp('2018-05-31 00:00:00'), 6),\n",
       " (Timestamp('2018-09-13 00:00:00'), 6),\n",
       " (Timestamp('2018-12-24 00:00:00'), 6),\n",
       " (Timestamp('2019-04-30 00:00:00'), 6),\n",
       " (Timestamp('2019-06-10 00:00:00'), 6),\n",
       " (Timestamp('2020-09-11 00:00:00'), 6),\n",
       " (Timestamp('2020-09-29 00:00:00'), 6),\n",
       " (Timestamp('2021-01-29 00:00:00'), 6),\n",
       " (Timestamp('2018-02-02 00:00:00'), 5),\n",
       " (Timestamp('2018-08-21 00:00:00'), 5),\n",
       " (Timestamp('2019-10-22 00:00:00'), 5),\n",
       " (Timestamp('2020-05-19 00:00:00'), 5),\n",
       " (Timestamp('2020-11-04 00:00:00'), 5),\n",
       " (Timestamp('2018-02-12 00:00:00'), 4),\n",
       " (Timestamp('2018-03-19 00:00:00'), 4),\n",
       " (Timestamp('2018-03-26 00:00:00'), 4),\n",
       " (Timestamp('2018-04-18 00:00:00'), 4),\n",
       " (Timestamp('2018-06-20 00:00:00'), 4),\n",
       " (Timestamp('2018-07-31 00:00:00'), 4),\n",
       " (Timestamp('2018-08-07 00:00:00'), 4),\n",
       " (Timestamp('2018-09-04 00:00:00'), 4),\n",
       " (Timestamp('2018-10-12 00:00:00'), 4),\n",
       " (Timestamp('2018-10-19 00:00:00'), 4),\n",
       " (Timestamp('2019-02-01 00:00:00'), 4),\n",
       " (Timestamp('2019-04-12 00:00:00'), 4),\n",
       " (Timestamp('2019-08-07 00:00:00'), 4),\n",
       " (Timestamp('2019-11-14 00:00:00'), 4),\n",
       " (Timestamp('2019-11-26 00:00:00'), 4),\n",
       " (Timestamp('2019-12-03 00:00:00'), 4),\n",
       " (Timestamp('2020-03-02 00:00:00'), 4),\n",
       " (Timestamp('2020-04-14 00:00:00'), 4),\n",
       " (Timestamp('2020-05-26 00:00:00'), 4),\n",
       " (Timestamp('2020-06-30 00:00:00'), 4),\n",
       " (Timestamp('2020-11-20 00:00:00'), 4),\n",
       " (Timestamp('2020-12-17 00:00:00'), 4),\n",
       " (Timestamp('2021-01-12 00:00:00'), 4),\n",
       " (Timestamp('2018-11-27 00:00:00'), 3),\n",
       " (Timestamp('2018-12-28 00:00:00'), 3),\n",
       " (Timestamp('2019-03-27 00:00:00'), 3),\n",
       " (Timestamp('2019-05-27 00:00:00'), 3),\n",
       " (Timestamp('2019-06-19 00:00:00'), 3),\n",
       " (Timestamp('2019-11-01 00:00:00'), 3),\n",
       " (Timestamp('2019-12-24 00:00:00'), 3),\n",
       " (Timestamp('2020-03-17 00:00:00'), 3),\n",
       " (Timestamp('2020-03-31 00:00:00'), 3),\n",
       " (Timestamp('2020-06-08 00:00:00'), 3),\n",
       " (Timestamp('2020-07-17 00:00:00'), 3),\n",
       " (Timestamp('2020-10-19 00:00:00'), 3),\n",
       " (Timestamp('2020-11-30 00:00:00'), 3),\n",
       " (Timestamp('2020-12-25 00:00:00'), 3),\n",
       " (Timestamp('2018-01-11 00:00:00'), 2),\n",
       " (Timestamp('2018-01-16 00:00:00'), 2),\n",
       " (Timestamp('2018-03-01 00:00:00'), 2),\n",
       " (Timestamp('2018-03-06 00:00:00'), 2),\n",
       " (Timestamp('2018-04-09 00:00:00'), 2),\n",
       " (Timestamp('2018-04-24 00:00:00'), 2),\n",
       " (Timestamp('2018-04-27 00:00:00'), 2),\n",
       " (Timestamp('2018-05-15 00:00:00'), 2),\n",
       " (Timestamp('2018-05-18 00:00:00'), 2),\n",
       " (Timestamp('2018-06-05 00:00:00'), 2),\n",
       " (Timestamp('2018-06-12 00:00:00'), 2),\n",
       " (Timestamp('2018-07-06 00:00:00'), 2),\n",
       " (Timestamp('2018-09-18 00:00:00'), 2),\n",
       " (Timestamp('2018-11-12 00:00:00'), 2),\n",
       " (Timestamp('2018-12-12 00:00:00'), 2),\n",
       " (Timestamp('2019-02-28 00:00:00'), 2),\n",
       " (Timestamp('2019-03-15 00:00:00'), 2),\n",
       " (Timestamp('2019-05-21 00:00:00'), 2),\n",
       " (Timestamp('2019-06-26 00:00:00'), 2),\n",
       " (Timestamp('2019-09-02 00:00:00'), 2),\n",
       " (Timestamp('2019-09-18 00:00:00'), 2),\n",
       " (Timestamp('2019-09-27 00:00:00'), 2),\n",
       " (Timestamp('2019-10-09 00:00:00'), 2),\n",
       " (Timestamp('2019-10-25 00:00:00'), 2),\n",
       " (Timestamp('2020-01-17 00:00:00'), 2),\n",
       " (Timestamp('2020-02-04 00:00:00'), 2),\n",
       " (Timestamp('2020-04-07 00:00:00'), 2),\n",
       " (Timestamp('2020-04-30 00:00:00'), 2),\n",
       " (Timestamp('2020-06-12 00:00:00'), 2),\n",
       " (Timestamp('2020-07-28 00:00:00'), 2),\n",
       " (Timestamp('2020-08-10 00:00:00'), 2),\n",
       " (Timestamp('2020-08-13 00:00:00'), 2),\n",
       " (Timestamp('2020-08-21 00:00:00'), 2),\n",
       " (Timestamp('2020-11-12 00:00:00'), 2),\n",
       " (Timestamp('2020-12-04 00:00:00'), 2),\n",
       " (Timestamp('2020-12-10 00:00:00'), 2),\n",
       " (Timestamp('2020-12-30 00:00:00'), 2),\n",
       " (Timestamp('2018-01-18 00:00:00'), 1),\n",
       " (Timestamp('2018-02-26 00:00:00'), 1),\n",
       " (Timestamp('2018-03-08 00:00:00'), 1),\n",
       " (Timestamp('2018-03-29 00:00:00'), 1),\n",
       " (Timestamp('2018-04-11 00:00:00'), 1),\n",
       " (Timestamp('2018-05-03 00:00:00'), 1),\n",
       " (Timestamp('2018-05-10 00:00:00'), 1),\n",
       " (Timestamp('2018-06-22 00:00:00'), 1),\n",
       " (Timestamp('2018-06-28 00:00:00'), 1),\n",
       " (Timestamp('2018-07-03 00:00:00'), 1),\n",
       " (Timestamp('2018-07-12 00:00:00'), 1),\n",
       " (Timestamp('2018-07-17 00:00:00'), 1),\n",
       " (Timestamp('2018-08-09 00:00:00'), 1),\n",
       " (Timestamp('2018-08-23 00:00:00'), 1),\n",
       " (Timestamp('2018-09-21 00:00:00'), 1),\n",
       " (Timestamp('2018-09-26 00:00:00'), 1),\n",
       " (Timestamp('2018-09-28 00:00:00'), 1),\n",
       " (Timestamp('2018-10-24 00:00:00'), 1),\n",
       " (Timestamp('2018-10-26 00:00:00'), 1),\n",
       " (Timestamp('2018-10-30 00:00:00'), 1),\n",
       " (Timestamp('2018-11-07 00:00:00'), 1),\n",
       " (Timestamp('2018-11-21 00:00:00'), 1),\n",
       " (Timestamp('2018-11-30 00:00:00'), 1),\n",
       " (Timestamp('2018-12-07 00:00:00'), 1),\n",
       " (Timestamp('2019-01-03 00:00:00'), 1),\n",
       " (Timestamp('2019-01-15 00:00:00'), 1),\n",
       " (Timestamp('2019-01-18 00:00:00'), 1),\n",
       " (Timestamp('2019-01-23 00:00:00'), 1),\n",
       " (Timestamp('2019-02-18 00:00:00'), 1),\n",
       " (Timestamp('2019-02-20 00:00:00'), 1),\n",
       " (Timestamp('2019-03-11 00:00:00'), 1),\n",
       " (Timestamp('2019-03-21 00:00:00'), 1),\n",
       " (Timestamp('2019-03-29 00:00:00'), 1),\n",
       " (Timestamp('2019-04-16 00:00:00'), 1),\n",
       " (Timestamp('2019-04-19 00:00:00'), 1),\n",
       " (Timestamp('2019-05-07 00:00:00'), 1),\n",
       " (Timestamp('2019-05-14 00:00:00'), 1),\n",
       " (Timestamp('2019-06-13 00:00:00'), 1),\n",
       " (Timestamp('2019-07-01 00:00:00'), 1),\n",
       " (Timestamp('2019-07-19 00:00:00'), 1),\n",
       " (Timestamp('2019-07-23 00:00:00'), 1),\n",
       " (Timestamp('2019-08-12 00:00:00'), 1),\n",
       " (Timestamp('2019-08-14 00:00:00'), 1),\n",
       " (Timestamp('2019-08-23 00:00:00'), 1),\n",
       " (Timestamp('2019-08-27 00:00:00'), 1),\n",
       " (Timestamp('2019-09-12 00:00:00'), 1),\n",
       " (Timestamp('2019-09-24 00:00:00'), 1),\n",
       " (Timestamp('2019-11-07 00:00:00'), 1),\n",
       " (Timestamp('2019-11-18 00:00:00'), 1),\n",
       " (Timestamp('2019-12-30 00:00:00'), 1),\n",
       " (Timestamp('2020-01-09 00:00:00'), 1),\n",
       " (Timestamp('2020-01-13 00:00:00'), 1),\n",
       " (Timestamp('2020-01-22 00:00:00'), 1),\n",
       " (Timestamp('2020-02-10 00:00:00'), 1),\n",
       " (Timestamp('2020-02-14 00:00:00'), 1),\n",
       " (Timestamp('2020-03-10 00:00:00'), 1),\n",
       " (Timestamp('2020-03-24 00:00:00'), 1),\n",
       " (Timestamp('2020-04-27 00:00:00'), 1),\n",
       " (Timestamp('2020-05-08 00:00:00'), 1),\n",
       " (Timestamp('2020-05-29 00:00:00'), 1),\n",
       " (Timestamp('2020-07-13 00:00:00'), 1),\n",
       " (Timestamp('2020-08-05 00:00:00'), 1),\n",
       " (Timestamp('2020-08-17 00:00:00'), 1),\n",
       " (Timestamp('2020-08-25 00:00:00'), 1),\n",
       " (Timestamp('2020-08-27 00:00:00'), 1),\n",
       " (Timestamp('2020-09-17 00:00:00'), 1),\n",
       " (Timestamp('2020-10-26 00:00:00'), 1),\n",
       " (Timestamp('2020-11-09 00:00:00'), 1),\n",
       " (Timestamp('2021-01-14 00:00:00'), 1),\n",
       " (Timestamp('2021-01-20 00:00:00'), 1),\n",
       " (Timestamp('2017-12-29 00:00:00'), 0),\n",
       " (Timestamp('2018-01-02 00:00:00'), 0),\n",
       " (Timestamp('2018-01-03 00:00:00'), 0),\n",
       " (Timestamp('2018-01-04 00:00:00'), 0),\n",
       " (Timestamp('2018-01-05 00:00:00'), 0),\n",
       " (Timestamp('2018-01-08 00:00:00'), 0),\n",
       " (Timestamp('2018-01-19 00:00:00'), 0),\n",
       " (Timestamp('2018-01-22 00:00:00'), 0),\n",
       " (Timestamp('2018-01-23 00:00:00'), 0),\n",
       " (Timestamp('2018-01-24 00:00:00'), 0),\n",
       " (Timestamp('2018-01-25 00:00:00'), 0),\n",
       " (Timestamp('2018-02-05 00:00:00'), 0),\n",
       " (Timestamp('2018-02-13 00:00:00'), 0),\n",
       " (Timestamp('2018-02-14 00:00:00'), 0),\n",
       " (Timestamp('2018-02-22 00:00:00'), 0),\n",
       " (Timestamp('2018-03-09 00:00:00'), 0),\n",
       " (Timestamp('2018-03-12 00:00:00'), 0),\n",
       " (Timestamp('2018-03-27 00:00:00'), 0),\n",
       " (Timestamp('2018-03-30 00:00:00'), 0),\n",
       " (Timestamp('2018-04-02 00:00:00'), 0),\n",
       " (Timestamp('2018-04-19 00:00:00'), 0),\n",
       " (Timestamp('2018-05-04 00:00:00'), 0),\n",
       " (Timestamp('2018-05-07 00:00:00'), 0),\n",
       " (Timestamp('2018-05-08 00:00:00'), 0),\n",
       " (Timestamp('2018-05-21 00:00:00'), 0),\n",
       " (Timestamp('2018-05-22 00:00:00'), 0),\n",
       " (Timestamp('2018-06-06 00:00:00'), 0),\n",
       " (Timestamp('2018-06-07 00:00:00'), 0),\n",
       " (Timestamp('2018-06-25 00:00:00'), 0),\n",
       " (Timestamp('2018-06-26 00:00:00'), 0),\n",
       " (Timestamp('2018-06-29 00:00:00'), 0),\n",
       " (Timestamp('2018-07-09 00:00:00'), 0),\n",
       " (Timestamp('2018-07-10 00:00:00'), 0),\n",
       " (Timestamp('2018-07-13 00:00:00'), 0),\n",
       " (Timestamp('2018-07-18 00:00:00'), 0),\n",
       " (Timestamp('2018-07-19 00:00:00'), 0),\n",
       " (Timestamp('2018-07-20 00:00:00'), 0),\n",
       " (Timestamp('2018-07-23 00:00:00'), 0),\n",
       " (Timestamp('2018-07-24 00:00:00'), 0),\n",
       " (Timestamp('2018-08-10 00:00:00'), 0),\n",
       " (Timestamp('2018-08-13 00:00:00'), 0),\n",
       " (Timestamp('2018-08-24 00:00:00'), 0),\n",
       " (Timestamp('2018-08-27 00:00:00'), 0),\n",
       " (Timestamp('2018-08-28 00:00:00'), 0),\n",
       " (Timestamp('2018-09-19 00:00:00'), 0),\n",
       " (Timestamp('2018-10-22 00:00:00'), 0),\n",
       " (Timestamp('2018-10-31 00:00:00'), 0),\n",
       " (Timestamp('2018-11-01 00:00:00'), 0),\n",
       " (Timestamp('2018-11-02 00:00:00'), 0),\n",
       " (Timestamp('2018-11-05 00:00:00'), 0),\n",
       " (Timestamp('2018-11-13 00:00:00'), 0),\n",
       " (Timestamp('2018-11-14 00:00:00'), 0),\n",
       " (Timestamp('2018-11-15 00:00:00'), 0),\n",
       " (Timestamp('2018-11-16 00:00:00'), 0),\n",
       " (Timestamp('2018-11-19 00:00:00'), 0),\n",
       " (Timestamp('2018-11-28 00:00:00'), 0),\n",
       " (Timestamp('2018-12-03 00:00:00'), 0),\n",
       " (Timestamp('2018-12-04 00:00:00'), 0),\n",
       " (Timestamp('2018-12-05 00:00:00'), 0),\n",
       " (Timestamp('2018-12-13 00:00:00'), 0),\n",
       " (Timestamp('2019-01-04 00:00:00'), 0),\n",
       " (Timestamp('2019-01-07 00:00:00'), 0),\n",
       " (Timestamp('2019-01-08 00:00:00'), 0),\n",
       " (Timestamp('2019-01-09 00:00:00'), 0),\n",
       " (Timestamp('2019-01-10 00:00:00'), 0),\n",
       " (Timestamp('2019-01-11 00:00:00'), 0),\n",
       " (Timestamp('2019-01-16 00:00:00'), 0),\n",
       " (Timestamp('2019-01-21 00:00:00'), 0),\n",
       " (Timestamp('2019-01-24 00:00:00'), 0),\n",
       " (Timestamp('2019-01-25 00:00:00'), 0),\n",
       " (Timestamp('2019-02-11 00:00:00'), 0),\n",
       " (Timestamp('2019-02-12 00:00:00'), 0),\n",
       " (Timestamp('2019-02-13 00:00:00'), 0),\n",
       " (Timestamp('2019-02-14 00:00:00'), 0),\n",
       " (Timestamp('2019-02-21 00:00:00'), 0),\n",
       " (Timestamp('2019-02-22 00:00:00'), 0),\n",
       " (Timestamp('2019-02-25 00:00:00'), 0),\n",
       " (Timestamp('2019-03-01 00:00:00'), 0),\n",
       " (Timestamp('2019-03-04 00:00:00'), 0),\n",
       " (Timestamp('2019-03-05 00:00:00'), 0),\n",
       " (Timestamp('2019-03-06 00:00:00'), 0),\n",
       " (Timestamp('2019-03-07 00:00:00'), 0),\n",
       " (Timestamp('2019-03-12 00:00:00'), 0),\n",
       " (Timestamp('2019-03-18 00:00:00'), 0),\n",
       " (Timestamp('2019-03-19 00:00:00'), 0),\n",
       " (Timestamp('2019-04-01 00:00:00'), 0),\n",
       " (Timestamp('2019-04-02 00:00:00'), 0),\n",
       " (Timestamp('2019-04-03 00:00:00'), 0),\n",
       " (Timestamp('2019-04-04 00:00:00'), 0),\n",
       " (Timestamp('2019-04-17 00:00:00'), 0),\n",
       " (Timestamp('2019-05-08 00:00:00'), 0),\n",
       " (Timestamp('2019-05-09 00:00:00'), 0),\n",
       " (Timestamp('2019-05-10 00:00:00'), 0),\n",
       " (Timestamp('2019-05-15 00:00:00'), 0),\n",
       " (Timestamp('2019-05-16 00:00:00'), 0),\n",
       " (Timestamp('2019-05-28 00:00:00'), 0),\n",
       " (Timestamp('2019-05-29 00:00:00'), 0),\n",
       " (Timestamp('2019-06-11 00:00:00'), 0),\n",
       " (Timestamp('2019-06-20 00:00:00'), 0),\n",
       " (Timestamp('2019-06-21 00:00:00'), 0),\n",
       " (Timestamp('2019-06-27 00:00:00'), 0),\n",
       " (Timestamp('2019-07-15 00:00:00'), 0),\n",
       " (Timestamp('2019-07-16 00:00:00'), 0),\n",
       " (Timestamp('2019-07-17 00:00:00'), 0),\n",
       " (Timestamp('2019-07-24 00:00:00'), 0),\n",
       " (Timestamp('2019-07-25 00:00:00'), 0),\n",
       " (Timestamp('2019-07-26 00:00:00'), 0),\n",
       " (Timestamp('2019-07-29 00:00:00'), 0),\n",
       " (Timestamp('2019-07-30 00:00:00'), 0),\n",
       " (Timestamp('2019-07-31 00:00:00'), 0),\n",
       " (Timestamp('2019-08-08 00:00:00'), 0),\n",
       " (Timestamp('2019-08-15 00:00:00'), 0),\n",
       " (Timestamp('2019-08-16 00:00:00'), 0),\n",
       " (Timestamp('2019-08-19 00:00:00'), 0),\n",
       " (Timestamp('2019-08-20 00:00:00'), 0),\n",
       " (Timestamp('2019-08-21 00:00:00'), 0),\n",
       " (Timestamp('2019-08-28 00:00:00'), 0),\n",
       " (Timestamp('2019-09-03 00:00:00'), 0),\n",
       " (Timestamp('2019-09-04 00:00:00'), 0),\n",
       " (Timestamp('2019-09-05 00:00:00'), 0),\n",
       " (Timestamp('2019-09-06 00:00:00'), 0),\n",
       " (Timestamp('2019-09-09 00:00:00'), 0),\n",
       " (Timestamp('2019-09-10 00:00:00'), 0),\n",
       " (Timestamp('2019-09-19 00:00:00'), 0),\n",
       " (Timestamp('2019-09-20 00:00:00'), 0),\n",
       " (Timestamp('2019-10-10 00:00:00'), 0),\n",
       " (Timestamp('2019-10-11 00:00:00'), 0),\n",
       " (Timestamp('2019-10-14 00:00:00'), 0),\n",
       " (Timestamp('2019-10-28 00:00:00'), 0),\n",
       " (Timestamp('2019-11-04 00:00:00'), 0),\n",
       " (Timestamp('2019-11-05 00:00:00'), 0),\n",
       " (Timestamp('2019-11-19 00:00:00'), 0),\n",
       " (Timestamp('2019-12-04 00:00:00'), 0),\n",
       " (Timestamp('2019-12-05 00:00:00'), 0),\n",
       " (Timestamp('2019-12-06 00:00:00'), 0),\n",
       " (Timestamp('2019-12-09 00:00:00'), 0),\n",
       " (Timestamp('2019-12-10 00:00:00'), 0),\n",
       " (Timestamp('2019-12-11 00:00:00'), 0),\n",
       " (Timestamp('2019-12-12 00:00:00'), 0),\n",
       " (Timestamp('2019-12-13 00:00:00'), 0),\n",
       " (Timestamp('2019-12-16 00:00:00'), 0),\n",
       " (Timestamp('2019-12-17 00:00:00'), 0),\n",
       " (Timestamp('2019-12-18 00:00:00'), 0),\n",
       " (Timestamp('2019-12-25 00:00:00'), 0),\n",
       " (Timestamp('2019-12-26 00:00:00'), 0),\n",
       " (Timestamp('2019-12-31 00:00:00'), 0),\n",
       " (Timestamp('2020-01-02 00:00:00'), 0),\n",
       " (Timestamp('2020-01-03 00:00:00'), 0),\n",
       " (Timestamp('2020-01-06 00:00:00'), 0),\n",
       " (Timestamp('2020-01-07 00:00:00'), 0),\n",
       " (Timestamp('2020-01-14 00:00:00'), 0),\n",
       " (Timestamp('2020-01-20 00:00:00'), 0),\n",
       " (Timestamp('2020-02-05 00:00:00'), 0),\n",
       " (Timestamp('2020-02-06 00:00:00'), 0),\n",
       " (Timestamp('2020-02-11 00:00:00'), 0),\n",
       " (Timestamp('2020-02-12 00:00:00'), 0),\n",
       " (Timestamp('2020-02-17 00:00:00'), 0),\n",
       " (Timestamp('2020-02-18 00:00:00'), 0),\n",
       " (Timestamp('2020-02-19 00:00:00'), 0),\n",
       " (Timestamp('2020-02-20 00:00:00'), 0),\n",
       " (Timestamp('2020-02-21 00:00:00'), 0),\n",
       " (Timestamp('2020-02-24 00:00:00'), 0),\n",
       " (Timestamp('2020-03-03 00:00:00'), 0),\n",
       " (Timestamp('2020-03-04 00:00:00'), 0),\n",
       " (Timestamp('2020-03-05 00:00:00'), 0),\n",
       " (Timestamp('2020-03-06 00:00:00'), 0),\n",
       " (Timestamp('2020-03-11 00:00:00'), 0),\n",
       " (Timestamp('2020-03-18 00:00:00'), 0),\n",
       " (Timestamp('2020-03-19 00:00:00'), 0),\n",
       " (Timestamp('2020-03-20 00:00:00'), 0),\n",
       " (Timestamp('2020-03-25 00:00:00'), 0),\n",
       " (Timestamp('2020-04-01 00:00:00'), 0),\n",
       " (Timestamp('2020-04-15 00:00:00'), 0),\n",
       " (Timestamp('2020-04-16 00:00:00'), 0),\n",
       " (Timestamp('2020-04-17 00:00:00'), 0),\n",
       " (Timestamp('2020-04-20 00:00:00'), 0),\n",
       " (Timestamp('2020-04-21 00:00:00'), 0),\n",
       " (Timestamp('2020-04-22 00:00:00'), 0),\n",
       " (Timestamp('2020-04-23 00:00:00'), 0),\n",
       " (Timestamp('2020-05-06 00:00:00'), 0),\n",
       " (Timestamp('2020-05-11 00:00:00'), 0),\n",
       " (Timestamp('2020-05-27 00:00:00'), 0),\n",
       " (Timestamp('2020-06-01 00:00:00'), 0),\n",
       " (Timestamp('2020-06-02 00:00:00'), 0),\n",
       " (Timestamp('2020-06-09 00:00:00'), 0),\n",
       " (Timestamp('2020-06-15 00:00:00'), 0),\n",
       " (Timestamp('2020-06-16 00:00:00'), 0),\n",
       " (Timestamp('2020-06-17 00:00:00'), 0),\n",
       " (Timestamp('2020-06-18 00:00:00'), 0),\n",
       " (Timestamp('2020-06-19 00:00:00'), 0),\n",
       " (Timestamp('2020-07-01 00:00:00'), 0),\n",
       " (Timestamp('2020-07-02 00:00:00'), 0),\n",
       " (Timestamp('2020-07-03 00:00:00'), 0),\n",
       " (Timestamp('2020-07-06 00:00:00'), 0),\n",
       " (Timestamp('2020-07-07 00:00:00'), 0),\n",
       " (Timestamp('2020-07-08 00:00:00'), 0),\n",
       " (Timestamp('2020-07-09 00:00:00'), 0),\n",
       " (Timestamp('2020-07-20 00:00:00'), 0),\n",
       " (Timestamp('2020-07-21 00:00:00'), 0),\n",
       " (Timestamp('2020-07-22 00:00:00'), 0),\n",
       " (Timestamp('2020-07-23 00:00:00'), 0),\n",
       " (Timestamp('2020-07-29 00:00:00'), 0),\n",
       " (Timestamp('2020-07-30 00:00:00'), 0),\n",
       " (Timestamp('2020-07-31 00:00:00'), 0),\n",
       " (Timestamp('2020-08-03 00:00:00'), 0),\n",
       " (Timestamp('2020-08-18 00:00:00'), 0),\n",
       " (Timestamp('2020-08-28 00:00:00'), 0),\n",
       " (Timestamp('2020-08-31 00:00:00'), 0),\n",
       " (Timestamp('2020-09-01 00:00:00'), 0),\n",
       " (Timestamp('2020-09-02 00:00:00'), 0),\n",
       " (Timestamp('2020-09-14 00:00:00'), 0),\n",
       " (Timestamp('2020-09-15 00:00:00'), 0),\n",
       " (Timestamp('2020-09-18 00:00:00'), 0),\n",
       " (Timestamp('2020-09-30 00:00:00'), 0),\n",
       " (Timestamp('2020-10-09 00:00:00'), 0),\n",
       " (Timestamp('2020-10-12 00:00:00'), 0),\n",
       " (Timestamp('2020-10-13 00:00:00'), 0),\n",
       " (Timestamp('2020-10-20 00:00:00'), 0),\n",
       " (Timestamp('2020-10-21 00:00:00'), 0),\n",
       " (Timestamp('2020-10-22 00:00:00'), 0),\n",
       " (Timestamp('2020-10-27 00:00:00'), 0),\n",
       " (Timestamp('2020-11-05 00:00:00'), 0),\n",
       " (Timestamp('2020-11-13 00:00:00'), 0),\n",
       " (Timestamp('2020-11-23 00:00:00'), 0),\n",
       " (Timestamp('2020-11-24 00:00:00'), 0),\n",
       " (Timestamp('2020-12-01 00:00:00'), 0),\n",
       " (Timestamp('2020-12-07 00:00:00'), 0),\n",
       " (Timestamp('2020-12-18 00:00:00'), 0),\n",
       " (Timestamp('2020-12-21 00:00:00'), 0),\n",
       " (Timestamp('2020-12-31 00:00:00'), 0),\n",
       " (Timestamp('2021-01-04 00:00:00'), 0),\n",
       " (Timestamp('2021-01-05 00:00:00'), 0),\n",
       " (Timestamp('2021-01-15 00:00:00'), 0),\n",
       " (Timestamp('2021-01-18 00:00:00'), 0),\n",
       " (Timestamp('2021-01-21 00:00:00'), 0)]"
      ]
     },
     "metadata": {},
     "execution_count": 99
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_excel('temp1.xls')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "日期         2019-07-12 00:00:00\n",
       "指数                     1118.22\n",
       "成交额(亿元)                 36.586\n",
       "涨跌                       2.158\n",
       "涨跌额                      0.193\n",
       "转债数目                       168\n",
       "剩余规模                   2715.44\n",
       "涨                         True\n",
       "Name: 371, dtype: object"
      ]
     },
     "metadata": {},
     "execution_count": 30
    }
   ],
   "source": [
    "df.iloc[371]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\nRangeIndex: 750 entries, 0 to 749\nData columns (total 8 columns):\n #   Column   Non-Null Count  Dtype         \n---  ------   --------------  -----         \n 0   日期       750 non-null    datetime64[ns]\n 1   指数       750 non-null    float64       \n 2   成交额(亿元)  750 non-null    float64       \n 3   涨跌       750 non-null    float64       \n 4   涨跌额      750 non-null    float64       \n 5   转债数目     750 non-null    float64       \n 6   剩余规模     750 non-null    float64       \n 7   涨        750 non-null    bool          \ndtypes: bool(1), datetime64[ns](1), float64(6)\nmemory usage: 41.9 KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['日期']=pd.to_datetime(df['日期'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\nRangeIndex: 750 entries, 0 to 749\nData columns (total 8 columns):\n #   Column   Non-Null Count  Dtype         \n---  ------   --------------  -----         \n 0   日期       750 non-null    datetime64[ns]\n 1   指数       750 non-null    float64       \n 2   成交额(亿元)  750 non-null    float64       \n 3   涨跌       750 non-null    float64       \n 4   涨跌额      750 non-null    float64       \n 5   转债数目     750 non-null    float64       \n 6   剩余规模     750 non-null    float64       \n 7   涨        750 non-null    bool          \ndtypes: bool(1), datetime64[ns](1), float64(6)\nmemory usage: 41.9 KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "          日期       指数  成交额(亿元)      涨跌    涨跌额  转债数目     剩余规模     涨\n",
       "0 2017-12-29  1000.00   10.581   0.000  0.000  36.0  853.790  True\n",
       "1 2018-01-02  1008.83   13.936   8.831  0.883  36.0  690.602  True\n",
       "2 2018-01-03  1018.81   15.964   9.977  0.989  37.0  691.246  True\n",
       "3 2018-01-04  1024.34   15.495   5.536  0.543  38.0  700.443  True\n",
       "4 2018-01-05  1034.66   19.973  10.311  1.007  38.0  700.443  True"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>指数</th>\n      <th>成交额(亿元)</th>\n      <th>涨跌</th>\n      <th>涨跌额</th>\n      <th>转债数目</th>\n      <th>剩余规模</th>\n      <th>涨</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2017-12-29</td>\n      <td>1000.00</td>\n      <td>10.581</td>\n      <td>0.000</td>\n      <td>0.000</td>\n      <td>36.0</td>\n      <td>853.790</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2018-01-02</td>\n      <td>1008.83</td>\n      <td>13.936</td>\n      <td>8.831</td>\n      <td>0.883</td>\n      <td>36.0</td>\n      <td>690.602</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2018-01-03</td>\n      <td>1018.81</td>\n      <td>15.964</td>\n      <td>9.977</td>\n      <td>0.989</td>\n      <td>37.0</td>\n      <td>691.246</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2018-01-04</td>\n      <td>1024.34</td>\n      <td>15.495</td>\n      <td>5.536</td>\n      <td>0.543</td>\n      <td>38.0</td>\n      <td>700.443</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2018-01-05</td>\n      <td>1034.66</td>\n      <td>19.973</td>\n      <td>10.311</td>\n      <td>1.007</td>\n      <td>38.0</td>\n      <td>700.443</td>\n      <td>True</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 37
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "df=df.set_index('日期',drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "                 指数  成交额(亿元)      涨跌    涨跌额  转债数目     剩余规模     涨\n",
       "日期                                                              \n",
       "2017-12-29  1000.00   10.581   0.000  0.000  36.0  853.790  True\n",
       "2018-01-02  1008.83   13.936   8.831  0.883  36.0  690.602  True\n",
       "2018-01-03  1018.81   15.964   9.977  0.989  37.0  691.246  True\n",
       "2018-01-04  1024.34   15.495   5.536  0.543  38.0  700.443  True\n",
       "2018-01-05  1034.66   19.973  10.311  1.007  38.0  700.443  True"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>指数</th>\n      <th>成交额(亿元)</th>\n      <th>涨跌</th>\n      <th>涨跌额</th>\n      <th>转债数目</th>\n      <th>剩余规模</th>\n      <th>涨</th>\n    </tr>\n    <tr>\n      <th>日期</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2017-12-29</th>\n      <td>1000.00</td>\n      <td>10.581</td>\n      <td>0.000</td>\n      <td>0.000</td>\n      <td>36.0</td>\n      <td>853.790</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2018-01-02</th>\n      <td>1008.83</td>\n      <td>13.936</td>\n      <td>8.831</td>\n      <td>0.883</td>\n      <td>36.0</td>\n      <td>690.602</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2018-01-03</th>\n      <td>1018.81</td>\n      <td>15.964</td>\n      <td>9.977</td>\n      <td>0.989</td>\n      <td>37.0</td>\n      <td>691.246</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2018-01-04</th>\n      <td>1024.34</td>\n      <td>15.495</td>\n      <td>5.536</td>\n      <td>0.543</td>\n      <td>38.0</td>\n      <td>700.443</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2018-01-05</th>\n      <td>1034.66</td>\n      <td>19.973</td>\n      <td>10.311</td>\n      <td>1.007</td>\n      <td>38.0</td>\n      <td>700.443</td>\n      <td>True</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 39
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_w = df.resample('W')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "<pandas.core.resample.DatetimeIndexResampler object at 0x0000023F5F1C27C0>"
      ]
     },
     "metadata": {},
     "execution_count": 42
    }
   ],
   "source": [
    "df_w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_raise_w = df_w.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "                 指数   成交额(亿元)      涨跌    涨跌额    转债数目       剩余规模    涨\n",
       "日期                                                                  \n",
       "2017-12-31  1000.00    10.581   0.000  0.000    36.0    853.790  1.0\n",
       "2018-01-07  4086.64    65.368  34.655  3.422   149.0   2782.734  4.0\n",
       "2018-01-14  5143.54    77.460  -8.803 -0.851   188.0   3549.162  2.0\n",
       "2018-01-21  5095.12   113.991   1.900  0.196   208.0   3855.600  3.0\n",
       "2018-01-28  5261.99   192.046  32.378  3.117   225.0   4088.732  4.0\n",
       "...             ...       ...     ...    ...     ...        ...  ...\n",
       "2021-01-03  6041.51  2003.653  21.301  1.414  1312.0  18955.970  2.0\n",
       "2021-01-10  7754.99  3350.279   7.080  0.483  1650.0  23773.620  2.0\n",
       "2021-01-17  7625.34  2821.030  -7.005 -0.447  1663.0  23746.800  3.0\n",
       "2021-01-24  7732.26  2303.234  19.624  1.281  1694.0  25402.350  3.0\n",
       "2021-01-31  6074.66  1950.645 -56.376 -3.689  1357.0  20419.000  0.0\n",
       "\n",
       "[162 rows x 7 columns]"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>指数</th>\n      <th>成交额(亿元)</th>\n      <th>涨跌</th>\n      <th>涨跌额</th>\n      <th>转债数目</th>\n      <th>剩余规模</th>\n      <th>涨</th>\n    </tr>\n    <tr>\n      <th>日期</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2017-12-31</th>\n      <td>1000.00</td>\n      <td>10.581</td>\n      <td>0.000</td>\n      <td>0.000</td>\n      <td>36.0</td>\n      <td>853.790</td>\n      <td>1.0</td>\n    </tr>\n    <tr>\n      <th>2018-01-07</th>\n      <td>4086.64</td>\n      <td>65.368</td>\n      <td>34.655</td>\n      <td>3.422</td>\n      <td>149.0</td>\n      <td>2782.734</td>\n      <td>4.0</td>\n    </tr>\n    <tr>\n      <th>2018-01-14</th>\n      <td>5143.54</td>\n      <td>77.460</td>\n      <td>-8.803</td>\n      <td>-0.851</td>\n      <td>188.0</td>\n      <td>3549.162</td>\n      <td>2.0</td>\n    </tr>\n    <tr>\n      <th>2018-01-21</th>\n      <td>5095.12</td>\n      <td>113.991</td>\n      <td>1.900</td>\n      <td>0.196</td>\n      <td>208.0</td>\n      <td>3855.600</td>\n      <td>3.0</td>\n    </tr>\n    <tr>\n      <th>2018-01-28</th>\n      <td>5261.99</td>\n      <td>192.046</td>\n      <td>32.378</td>\n      <td>3.117</td>\n      <td>225.0</td>\n      <td>4088.732</td>\n      <td>4.0</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>2021-01-03</th>\n      <td>6041.51</td>\n      <td>2003.653</td>\n      <td>21.301</td>\n      <td>1.414</td>\n      <td>1312.0</td>\n      <td>18955.970</td>\n      <td>2.0</td>\n    </tr>\n    <tr>\n      <th>2021-01-10</th>\n      <td>7754.99</td>\n      <td>3350.279</td>\n      <td>7.080</td>\n      <td>0.483</td>\n      <td>1650.0</td>\n      <td>23773.620</td>\n      <td>2.0</td>\n    </tr>\n    <tr>\n      <th>2021-01-17</th>\n      <td>7625.34</td>\n      <td>2821.030</td>\n      <td>-7.005</td>\n      <td>-0.447</td>\n      <td>1663.0</td>\n      <td>23746.800</td>\n      <td>3.0</td>\n    </tr>\n    <tr>\n      <th>2021-01-24</th>\n      <td>7732.26</td>\n      <td>2303.234</td>\n      <td>19.624</td>\n      <td>1.281</td>\n      <td>1694.0</td>\n      <td>25402.350</td>\n      <td>3.0</td>\n    </tr>\n    <tr>\n      <th>2021-01-31</th>\n      <td>6074.66</td>\n      <td>1950.645</td>\n      <td>-56.376</td>\n      <td>-3.689</td>\n      <td>1357.0</td>\n      <td>20419.000</td>\n      <td>0.0</td>\n    </tr>\n  </tbody>\n</table>\n<p>162 rows × 7 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 44
    }
   ],
   "source": [
    "df_raise_w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_raise_w['涨'] = df_raise_w['涨跌额'].map(lambda x:True if x>=0 else False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def get_max_day_list(df):\n",
    "    max_day = 0\n",
    "    max_day_list =[]\n",
    "    for index,row in df.iterrows():\n",
    "        if row['涨跌额'] < 0 :\n",
    "            max_day+=1\n",
    "        else:\n",
    "            max_day_list.append((index,max_day))     \n",
    "            max_day=0\n",
    "\n",
    "    return max_day_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "max_week_list = get_max_day_list(df_raise_w)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "result_w = list(sorted(max_week_list,key=lambda x:x[1],reverse=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "[(Timestamp('2019-06-16 00:00:00', freq='W-SUN'), 7),\n",
       " (Timestamp('2018-05-06 00:00:00', freq='W-SUN'), 3),\n",
       " (Timestamp('2018-06-10 00:00:00', freq='W-SUN'), 3),\n",
       " (Timestamp('2019-01-06 00:00:00', freq='W-SUN'), 3),\n",
       " (Timestamp('2019-10-13 00:00:00', freq='W-SUN'), 3),\n",
       " (Timestamp('2019-11-10 00:00:00', freq='W-SUN'), 3),\n",
       " (Timestamp('2020-04-19 00:00:00', freq='W-SUN'), 3),\n",
       " (Timestamp('2020-05-31 00:00:00', freq='W-SUN'), 3),\n",
       " (Timestamp('2021-01-03 00:00:00', freq='W-SUN'), 3),\n",
       " (Timestamp('2018-02-18 00:00:00', freq='W-SUN'), 2)]"
      ]
     },
     "metadata": {},
     "execution_count": 50
    }
   ],
   "source": [
    "result_w[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "                 指数  成交额(亿元)      涨跌    涨跌额   转债数目      剩余规模      涨\n",
       "日期                                                                 \n",
       "2019-04-07  4824.84  397.231  48.309  4.095  532.0   8290.41   True\n",
       "2019-04-14  5977.16  364.510 -33.186 -2.753  687.0  11435.86  False\n",
       "2019-04-21  5916.45  444.118   7.095  0.603  706.0  11713.41   True\n",
       "2019-04-28  5794.55  447.095 -53.517 -4.575  743.0  11913.65  False\n",
       "2019-05-05  2249.26  141.187  -6.906 -0.598  302.0   4872.06  False\n",
       "2019-05-12  5519.59  450.270  -5.077 -0.376  780.0  12828.42  False\n",
       "2019-05-19  5631.25  346.777  -4.103 -0.344  793.0  13207.74  False\n",
       "2019-05-26  5566.35  271.664 -12.581 -1.122  800.0  13288.45  False\n",
       "2019-06-02  5552.85  240.247  -1.578 -0.140  800.0  13288.45  False\n",
       "2019-06-09  4344.55  213.357 -29.746 -2.715  639.0  10576.44  False\n",
       "2019-06-16  5464.00  285.589  13.287  1.247  800.0  13226.80   True\n",
       "2019-06-23  5489.88  297.800  27.847  2.539  799.0  13236.37   True\n",
       "2019-06-30  5584.12  257.804   4.160  0.376  806.0  13287.62   True\n",
       "2019-07-07  5676.44  398.209  11.787  1.059  818.0  13359.89   True\n",
       "2019-07-14  5589.32  214.716 -14.652 -1.295  832.0  13524.30  False\n",
       "2019-07-21  5603.55  186.546   1.506  0.136  841.0  13590.98   True\n",
       "2019-07-28  5590.20  221.445   7.484  0.672  843.0  13513.02   True"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>指数</th>\n      <th>成交额(亿元)</th>\n      <th>涨跌</th>\n      <th>涨跌额</th>\n      <th>转债数目</th>\n      <th>剩余规模</th>\n      <th>涨</th>\n    </tr>\n    <tr>\n      <th>日期</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2019-04-07</th>\n      <td>4824.84</td>\n      <td>397.231</td>\n      <td>48.309</td>\n      <td>4.095</td>\n      <td>532.0</td>\n      <td>8290.41</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2019-04-14</th>\n      <td>5977.16</td>\n      <td>364.510</td>\n      <td>-33.186</td>\n      <td>-2.753</td>\n      <td>687.0</td>\n      <td>11435.86</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>2019-04-21</th>\n      <td>5916.45</td>\n      <td>444.118</td>\n      <td>7.095</td>\n      <td>0.603</td>\n      <td>706.0</td>\n      <td>11713.41</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2019-04-28</th>\n      <td>5794.55</td>\n      <td>447.095</td>\n      <td>-53.517</td>\n      <td>-4.575</td>\n      <td>743.0</td>\n      <td>11913.65</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>2019-05-05</th>\n      <td>2249.26</td>\n      <td>141.187</td>\n      <td>-6.906</td>\n      <td>-0.598</td>\n      <td>302.0</td>\n      <td>4872.06</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>2019-05-12</th>\n      <td>5519.59</td>\n      <td>450.270</td>\n      <td>-5.077</td>\n      <td>-0.376</td>\n      <td>780.0</td>\n      <td>12828.42</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>2019-05-19</th>\n      <td>5631.25</td>\n      <td>346.777</td>\n      <td>-4.103</td>\n      <td>-0.344</td>\n      <td>793.0</td>\n      <td>13207.74</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>2019-05-26</th>\n      <td>5566.35</td>\n      <td>271.664</td>\n      <td>-12.581</td>\n      <td>-1.122</td>\n      <td>800.0</td>\n      <td>13288.45</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>2019-06-02</th>\n      <td>5552.85</td>\n      <td>240.247</td>\n      <td>-1.578</td>\n      <td>-0.140</td>\n      <td>800.0</td>\n      <td>13288.45</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>2019-06-09</th>\n      <td>4344.55</td>\n      <td>213.357</td>\n      <td>-29.746</td>\n      <td>-2.715</td>\n      <td>639.0</td>\n      <td>10576.44</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>2019-06-16</th>\n      <td>5464.00</td>\n      <td>285.589</td>\n      <td>13.287</td>\n      <td>1.247</td>\n      <td>800.0</td>\n      <td>13226.80</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2019-06-23</th>\n      <td>5489.88</td>\n      <td>297.800</td>\n      <td>27.847</td>\n      <td>2.539</td>\n      <td>799.0</td>\n      <td>13236.37</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2019-06-30</th>\n      <td>5584.12</td>\n      <td>257.804</td>\n      <td>4.160</td>\n      <td>0.376</td>\n      <td>806.0</td>\n      <td>13287.62</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2019-07-07</th>\n      <td>5676.44</td>\n      <td>398.209</td>\n      <td>11.787</td>\n      <td>1.059</td>\n      <td>818.0</td>\n      <td>13359.89</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2019-07-14</th>\n      <td>5589.32</td>\n      <td>214.716</td>\n      <td>-14.652</td>\n      <td>-1.295</td>\n      <td>832.0</td>\n      <td>13524.30</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>2019-07-21</th>\n      <td>5603.55</td>\n      <td>186.546</td>\n      <td>1.506</td>\n      <td>0.136</td>\n      <td>841.0</td>\n      <td>13590.98</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2019-07-28</th>\n      <td>5590.20</td>\n      <td>221.445</td>\n      <td>7.484</td>\n      <td>0.672</td>\n      <td>843.0</td>\n      <td>13513.02</td>\n      <td>True</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 53
    }
   ],
   "source": [
    "df_raise_w['2019-04':'2019-07']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "                 指数   成交额(亿元)      涨跌    涨跌额    转债数目      剩余规模      涨\n",
       "日期                                                                   \n",
       "2021-01-03  6041.51  2003.653  21.301  1.414  1312.0  18955.97   True\n",
       "2021-01-10  7754.99  3350.279   7.080  0.483  1650.0  23773.62   True\n",
       "2021-01-17  7625.34  2821.030  -7.005 -0.447  1663.0  23746.80  False\n",
       "2021-01-24  7732.26  2303.234  19.624  1.281  1694.0  25402.35   True\n",
       "2021-01-31  6074.66  1950.645 -56.376 -3.689  1357.0  20419.00  False"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>指数</th>\n      <th>成交额(亿元)</th>\n      <th>涨跌</th>\n      <th>涨跌额</th>\n      <th>转债数目</th>\n      <th>剩余规模</th>\n      <th>涨</th>\n    </tr>\n    <tr>\n      <th>日期</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2021-01-03</th>\n      <td>6041.51</td>\n      <td>2003.653</td>\n      <td>21.301</td>\n      <td>1.414</td>\n      <td>1312.0</td>\n      <td>18955.97</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2021-01-10</th>\n      <td>7754.99</td>\n      <td>3350.279</td>\n      <td>7.080</td>\n      <td>0.483</td>\n      <td>1650.0</td>\n      <td>23773.62</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2021-01-17</th>\n      <td>7625.34</td>\n      <td>2821.030</td>\n      <td>-7.005</td>\n      <td>-0.447</td>\n      <td>1663.0</td>\n      <td>23746.80</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>2021-01-24</th>\n      <td>7732.26</td>\n      <td>2303.234</td>\n      <td>19.624</td>\n      <td>1.281</td>\n      <td>1694.0</td>\n      <td>25402.35</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2021-01-31</th>\n      <td>6074.66</td>\n      <td>1950.645</td>\n      <td>-56.376</td>\n      <td>-3.689</td>\n      <td>1357.0</td>\n      <td>20419.00</td>\n      <td>False</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 54
    }
   ],
   "source": [
    "df_raise_w.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}